package dongshi.daddy.configuration;

import dongshi.daddy.other.HelloProperties;
import dongshi.daddy.other.Spokesman;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(HelloProperties.class)
@ConditionalOnExpression // 默认为true，即默认加载
@AllArgsConstructor
public class HelloAutoConfiguration implements InitializingBean {
    private final HelloProperties props;

    // 创建 Spokesman 的 spring bean
    @Bean
    public Spokesman createSpokesman() {
        return new Spokesman(props.getName());
    }

    // 仅仅为了打印props，没有其他特殊用途
    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("props isss: " + props.getName());
    }
}
